package com.itlong.cloud.commons.resource;

import com.itlong.cloud.POJO.DTO.app.AppUserAccountBalanceDTO;
import com.itlong.cloud.POJO.PO.AppUserAccountBalancePO;
import com.itlong.cloud.commons.service.IAccountBalanceService;
import com.itlong.cloud.paymenthub.IAccountBalanceServiceClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Map;

/**
 * <desc>
 * 账户余额及扣费暴露接口
 * </desc>
 *
 * @createDate 2018/4/23
 */
@RestController
public class AccountBalanceServiceResource implements IAccountBalanceServiceClient {

    @Autowired
    private IAccountBalanceService iAccountBalanceService;


    /**
     * <desc>
     *      根据userId查询余额
     * <desc/>
     * @param  userId   带查询的userId
     * @return 余额
     * @author Juguang.S
     * @createDate 2018/4/23
     */
    @Override
    @PostMapping(path = "/show/getBalanceByUserId")
    public BigDecimal getBalanceByUserId(@RequestParam("userId") String userId) {
        return iAccountBalanceService.getBalanceByUserId(userId);
    }

    /**
     * <desc>
     *      根据userId查询对象
     * <desc/>
     * @param  userId   带查询的userId
     * @return 余额
     * @author Juguang.S
     * @createDate 2018/4/23
     */
    @Override
    @PostMapping(path = "/show/getUser")
    public AppUserAccountBalancePO getUser(@RequestParam("userId") String userId) {
        return iAccountBalanceService.getUser(userId);
    }

    /**
     * <desc>
     *      扣费
     * <desc/>
     * @param
     * @return
     * @author Juguang.S
     * @createDate 2018/4/23
     */
    @Override
    @PostMapping(path = "/show/updateBalance")
    public Map<String, Object> updateBalance(@RequestBody AppUserAccountBalanceDTO appUserAccountBalanceDTO) {
        return iAccountBalanceService.updateBalance(appUserAccountBalanceDTO);
    }

    /**
     * <desc>
     *      检查当前订单状态是否为支付成功
     * </desc>
     *
     * @param billsId 账单号
     * @return
     * @author Jiaqi.X
     * @createDate 2018/04/27
     */
    @Override
    @PostMapping(path = "/show/checkTradeSuccess")
    public Boolean checkTradeSuccess(@RequestParam("billsId") String billsId,@RequestParam("userId") String userId,@RequestParam("tradeId") String tradeId){
        return iAccountBalanceService.checkTradeSuccess(billsId,userId,tradeId);
    }

    /**
     * <desc>
     *      更新余额流水来源id
     * </desc>
     *
     * @param recordId 订单id
     * @param sourceId  来源id
     * @return
     * @author Jiaqi.X
     * @createDate 2018/04/28
     */
    @PostMapping(path = "/show/updateTradeSourceId")
    public Integer updateTradeSourceId(@RequestParam("recordId") String recordId,@RequestParam("sourceId") String sourceId){
        return iAccountBalanceService.updateTradeSourceId(recordId,sourceId);
    }

    /**
     * <desc>
     *      根据账单ID查询月卡订单的截止时间
     * </desc>
     *
     * @param billId 订单id
     * @return
     * @author Juguang.S
     * @createDate 2018/11/12
     */
    @PostMapping(path = "/show/getMonthCardTime")
    public String getMonthCardTime(@RequestParam("billId") String billId){
        return iAccountBalanceService.getMonthCardTime(billId);
    }
}